# -*- coding: utf-8 -*-
# Description:
# Created: tangyu 2023/7/27
import json
from flask import request
from flask_restful import Resource

from app.main.service.performance_prediction_imitate import PerformancePredirtionImitate
from app.util.result import Result
from datetime import datetime

# 接口入口类，获取请求参数，返回响应，新加接口入口类添加一个新的class和post方法
class PerformancePredirtionImitateAPI(Resource):

    @staticmethod
    def post():
        request_data = json.loads(request.get_data().decode("utf-8"))
        if not isinstance(request_data.get('group_var',None),str):
            return Result.error_response("group_var输入错误")
        if not isinstance(request_data.get('modelname',None),str):
            return Result.error_response("modelname输入错误")
        if not isinstance(request_data.get('column',None),str):
            return Result.error_response("column输入错误")
        if not isinstance(request_data.get('reelKey',None),str):
            return Result.error_response("reelKey输入错误")
        if not isinstance(request_data.get('Y',None),str):
            return Result.error_response("Y输入错误")
        if request_data['data'] == []:
            return Result.error_response("data为空")
        result=PerformancePredirtionImitate().performance_imitate(request_data)

        # 最后返回响应将对应的结果传到下面这个方法中即可，支持base_entity及子类、base_entity及子类的列表、字典、df这几种类型，会自动转json返回
        return Result.success_response(result)
